package com.czwj.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.czwj.dao.BudgetMainMapper;
import com.czwj.dao.BudgetSubItemMapper;
import com.czwj.entities.BudgetMain;
import com.czwj.entities.BudgetSubItem;
import com.czwj.service.BudgetSubItemService;

@Service
public class BudgetSubItemServiceImpl implements BudgetSubItemService {
	@Resource
	BudgetSubItemMapper mapper;
	@Resource
	BudgetMainMapper mainmapper;
	@Override
	public List<BudgetSubItem> searchbylevel3(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.searchbylevel3(map);
	}

	@Override
	public int countbylevel3(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.countbylevel3(map);
	}

	@Override
	public int update(BudgetSubItem budgetSubItem) {
		// TODO Auto-generated method stub
		return this.mapper.updateByPrimaryKeySelective(budgetSubItem);
	}

	@Override
	public int insert(BudgetSubItem budgetSubItem) {
		// TODO Auto-generated method stub
		return this.mapper.insertSelective(budgetSubItem);
	}

	@Override
	public int updateStatus(int id) {
		// TODO Auto-generated method stub
		return this.mapper.updateStatus(id);
	}

	@Override
	public List<BudgetSubItem> searchbylevel1(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.searchbylevel1(map);
	}

	@Override
	public int countbylevel1(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.countbylevel1(map);
	}

	@Override
	public List<BudgetSubItem> searchbylevel2(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.searchbylevel2(map);
	}

	@Override
	public int countbylevel2(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.countbylevel2(map);
	}

	@Override
	public BudgetSubItem selectByPrimaryKey(int id) {
		// TODO Auto-generated method stub
		return this.mapper.selectByPrimaryKey(id);
	}

	@Transactional
	@Override
	public int review(BudgetSubItem subItem) {
		// TODO Auto-generated method stub
		int count = this.mapper.updateByPrimaryKeySelective(subItem);
		BudgetMain main = this.mainmapper.selectByPrimaryKey(subItem.getMainid());
		main.setMoney(Double.toString(Double.parseDouble(main.getMoney())+Double.parseDouble(subItem.getMoney())));
		count+=this.mainmapper.updateByPrimaryKeySelective(main);
		return count;
	}

	@Override
	public List<BudgetSubItem> searchReviewedLevel1(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.searchReviewedLevel1(map);
	}

	@Override
	public int countReviewedLevel1(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.countReviewedLevel1(map);
	}

	@Override
	public List<BudgetSubItem> searchReviewedLevel2(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.searchReviewedLevel2(map);
	}

	@Override
	public int countReviewedLevel2(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.countReviewedLevel2(map);
	}

	@Override
	public int remove(int id) {
		// TODO Auto-generated method stub
		return this.mapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<BudgetSubItem> getbudget(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.mapper.getbudget(map);
	}

	/** 
	* 
	* @param map
	* @return
	* @see com.czwj.service.BudgetSubItemService#search(java.util.Map)
	*/
	@Override
	public List<BudgetSubItem> search(Map<String,Object> map){
		// TODO Auto-generated method stub
		return this.mapper.search(map);
	}

	/** 
	* 
	* @param map
	* @return
	* @see com.czwj.service.BudgetSubItemService#count(java.util.Map)
	*/
	@Override
	public int count(Map<String,Object> map){
		// TODO Auto-generated method stub
		return this.mapper.count(map);
	}

}
